from django.shortcuts import render,HttpResponse,redirect

# Create your views here.

def login(request):
    if request.method == 'GET':
        return render(request,'login.html')
    elif request.method == 'POST':
        user = request.POST.get('username',None)
        password = request.POST.get('password', None)
        if user == 'Beam' and password == '123456':
            return redirect('/home')
        else:
            err_msg = '用户名或者密码错误'
            return render(request,'login.html',{'err_msg':err_msg})
    else:
        return HttpResponse('404')

userlist = [{'name':'Beam','gerder':'男'},{'name':'Mity','gerder':'女'}]

def home(request):
    if request.method == 'POST':
        u = request.POST.get('username')
        g = request.POST.get('gender')
        temp={'name':u,'gerder':g}
        userlist.append(temp)
    return render(request,'admin.html',{'ulists':userlist})